home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 5 / MacMania 5.toast / / Internet software / NewsWatcher / NW Source / Source / menus.c < prev    next >
Text File  |  1997-01-09  |  6KB  |  220 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.     menus.c
  4.  
  5.     This module manges the menus.
  6.     
  7.     Copyright © 1994-1997, Northwestern University.
  8.  
  9. ----------------------------------------------------------------------------*/
  10.  
  11. #include <stdio.h>
  12.  
  13. #include "glob.h"
  14. #include "menus.h"
  15. #include "menuutil.h"
  16. #include "strutil.h"
  17. #include "wind.h"
  18.  
  19.  
  20.  
  21. /*----------------------------------------------------------------------------
  22.     SetMenusTo
  23.     
  24.     Set the menus to a given state.
  25.     
  26.     Entry:    newAppleMenuState = new Apple menu enable/disable flags.
  27.             newFileMenuState = new File menu enable/disable flags.
  28.             newEditMenuState = new Edit menu enable/disable flags.
  29.             newNewsMenuState = new News menu enable/disable flags.
  30.             newSpecialMenuState = new Special menu enable/disable flags.
  31.             newWindMenuState = new Windows menu enable/disable flags.
  32. ----------------------------------------------------------------------------*/
  33.  
  34. void SetMenusTo (
  35.     unsigned long newAppleMenuState,
  36.     unsigned long newFileMenuState, 
  37.     unsigned long newEditMenuState,
  38.     unsigned long newNewsMenuState, 
  39.     unsigned long newSpecialMenuState, 
  40.     unsigned long newWindMenuState)
  41. {
  42.     Boolean r0, r1, r2, r3 ,r4, r5;
  43.     static unsigned long appleMenuState = 0;
  44.     static unsigned long fileMenuState = 0;
  45.     static unsigned long editMenuState = 0;
  46.     static unsigned long newsMenuState = 0;
  47.     static unsigned long specialMenuState = 0;
  48.     static unsigned long windMenuState = 0;
  49.  
  50.     r0 = AdjustOneMenu(kAppleMenu, 31, &appleMenuState, newAppleMenuState);
  51.     r1 = AdjustOneMenu(kFileMenu, kNumFileMenuItems, &fileMenuState, newFileMenuState);
  52.     r2 = AdjustOneMenu(kEditMenu, kNumEditMenuItems, &editMenuState, newEditMenuState);
  53.     r3 = AdjustOneMenu(kNewsMenu, kNumNewsMenuItems, &newsMenuState, newNewsMenuState);
  54.     r4 = AdjustOneMenu(kSpecialMenu, kNumSpecialMenuItems, &specialMenuState, newSpecialMenuState);
  55.     r5 = AdjustOneMenu(kWindMenu, kNumWindMenuItems, &windMenuState, newWindMenuState);
  56.     if (r0 || r1 || r2 || r3 || r4 || r5) DrawMenuBar();
  57. }
  58.  
  59.  
  60.  
  61. /*----------------------------------------------------------------------------
  62.     SetWindowsMenuShowHideFullGroupList
  63.     
  64.     Set the Windows menu command to "Show Full Group List" or 
  65.     "Hide Full Group List".
  66.     
  67.     Entry:    show = true to set to "Show Full Group List"
  68.                  = false to set to "Hide Full Group List"
  69. ----------------------------------------------------------------------------*/
  70.  
  71. void SetWindowsMenuShowHideFullGroupList (Boolean show)
  72. {
  73.     MenuHandle windMenu;
  74.     Str255 str;
  75.  
  76.     windMenu = GetMenuHandle(kWindMenu);
  77.     GetPString(show ? kStrShowFullGroupList : kStrHideFullGroupList, str);
  78.     SetMenuItemText(windMenu, kShowHideFullGroupListItem, str);
  79. }
  80.  
  81.  
  82.  
  83. /*----------------------------------------------------------------------------
  84.     SetEditMenuShowHideDetails
  85.     
  86.     Set the Edit menu command to "Show Details" or "Hide Details".
  87.     
  88.     Entry:    show = true to set to "Show Details"
  89.                  = false to set to "Hide Details"
  90. ----------------------------------------------------------------------------*/
  91.  
  92. void SetEditMenuShowHideDetails (Boolean show)
  93. {
  94.     MenuHandle editMenu;
  95.     Str255 str;
  96.  
  97.     editMenu = GetMenuHandle(kEditMenu);
  98.     GetPString(show ? kStrShowHeader : kStrHideHeader, str);
  99.     SetMenuItemText(editMenu, kShowHideDetailsItem, str);
  100. }
  101.  
  102.  
  103.  
  104. /*----------------------------------------------------------------------------
  105.     AdjustExtractBinariesCommand
  106.     
  107.     Adjust the "Extract Binaries" command in the "Special" menu.
  108.     The command should end in an ellipsis iff there is no default
  109.     download folder configured.
  110. ----------------------------------------------------------------------------*/
  111.  
  112. void AdjustExtractBinariesCommand (void)
  113. {
  114.     MenuHandle specialMenu;
  115.     Str255 str;
  116.     unsigned char len;
  117.     
  118.     specialMenu = GetMenuHandle(kSpecialMenu);
  119.     GetMenuItemText(specialMenu, kExtractBinariesItem, str);
  120.     len = str[0];
  121.     if (gPrefs.savedBinDefaultFolder && str[len] == '.') {
  122.         str[0] = len-3;
  123.         SetMenuItemText(specialMenu, kExtractBinariesItem, str);
  124.     } else if (!gPrefs.savedBinDefaultFolder && str[len] != '.') {
  125.         str[0] = len+3;
  126.         str[len+1] = str[len+2] = str[len+3] = '.';
  127.         SetMenuItemText(specialMenu, kExtractBinariesItem, str);
  128.     }
  129. }
  130.  
  131.  
  132.  
  133. /*----------------------------------------------------------------------------
  134.     AdjustCycleWindowsCommand
  135.     
  136.     Adjust the "Cycle Windows" command in the "Windows" menu.
  137.     "Cycle Windows" should be enabled iff more than one visible window is open.
  138. ----------------------------------------------------------------------------*/
  139.  
  140. void AdjustCycleWindowsCommand (void)
  141. {
  142.     WindowPtr wind;
  143.     WindowPeek peek;
  144.     short numVis = 0;
  145.     MenuHandle windowsMenu;
  146.     
  147.     wind = FrontWindow();
  148.     while (wind != nil) {
  149.         peek = (WindowPeek)wind;
  150.         if (peek->visible) {
  151.             numVis++;
  152.             if (numVis >= 2) break;
  153.         }
  154.         wind = (WindowPtr)peek->nextWindow;
  155.     }
  156.     windowsMenu = GetMenuHandle(kWindMenu);
  157.     if (numVis >= 2) {
  158.         EnableItem(windowsMenu, kCycleWindowsItem);
  159.     } else {
  160.         DisableItem(windowsMenu, kCycleWindowsItem);
  161.     }
  162. }
  163.  
  164.  
  165.  
  166. /*----------------------------------------------------------------------------
  167.     AdjustMenuHelpBalloons
  168.     
  169.     Adjust the main menu bar help balloons.
  170.     
  171.     Entry:    term = true if program is terminating, in which case the
  172.                 menu help balloons are reset to their default state.
  173.                 
  174.     There are four sets of 'hmnu' resources for the main menus. This
  175.     function is called at idle time to switch between the sets when
  176.     necessary.
  177.     
  178.     Normal set: resource id = menu id.
  179.         
  180.     Startup bad set: resource id = 1000 + menu id.
  181.         Used when there is a problem starting up.
  182.     
  183.     Dialog set: resource id = 2000 + menu id.
  184.         Used when a dialog or alert is on the screen.
  185.         
  186.     Busy set: resource id = 3000 + menu id.
  187.         Used during long operations.
  188.         
  189.     This function also makes sure the menus are disabled if Balloon 
  190.     help is enabled and there is a long operation in progress.
  191. ----------------------------------------------------------------------------*/
  192.  
  193. void AdjustMenuHelpBalloons (Boolean term)
  194. {
  195.     TWindowKind kind;
  196.     static short curState = 0;
  197.     short newState, i;
  198.     
  199.     if (term) {
  200.         newState = 0;
  201.     } else {
  202.         kind = GetMyWindowKind(FrontWindow());
  203.         if (kind == kDialog) {
  204.             newState = 2000;
  205.         } else if (gLongOperation) {
  206.             newState = 3000;
  207.             if (HMGetBalloons()) 
  208.                 SetMenusTo(kAppleOnlyAboutDisabled, 0, 0, 0, 0, 0);
  209.         } else if (gStartupOK) {
  210.             newState = 0;
  211.         } else {
  212.             newState = 1000;
  213.         }
  214.     }
  215.     if (curState == newState) return;
  216.     for (i = kAppleMenu; i <= kWindMenu; i++)
  217.         HMSetMenuResID(i, newState == 0 ? -1 : i + newState);
  218.     curState = newState;
  219. }
  220.